from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-19 14:02:26.436196
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 19, Apr, 2022
Time: 14:02:31
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.0124
Nobs: 631.000 HQIC: -49.4003
Log likelihood: 7695.38 FPE: 2.74617e-22
AIC: -49.6467 Det(Omega_mle): 2.38380e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.329546 0.062949 5.235 0.000
L1.Burgenland 0.106166 0.039688 2.675 0.007
L1.Kärnten -0.110614 0.020797 -5.319 0.000
L1.Niederösterreich 0.195945 0.082929 2.363 0.018
L1.Oberösterreich 0.120132 0.081788 1.469 0.142
L1.Salzburg 0.259613 0.042107 6.166 0.000
L1.Steiermark 0.043398 0.055411 0.783 0.434
L1.Tirol 0.105175 0.044866 2.344 0.019
L1.Vorarlberg -0.065075 0.039578 -1.644 0.100
L1.Wien 0.021890 0.072584 0.302 0.763
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.045430 0.134704 0.337 0.736
L1.Burgenland -0.036498 0.084929 -0.430 0.667
L1.Kärnten 0.041639 0.044503 0.936 0.349
L1.Niederösterreich -0.199715 0.177460 -1.125 0.260
L1.Oberösterreich 0.454557 0.175017 2.597 0.009
L1.Salzburg 0.283670 0.090104 3.148 0.002
L1.Steiermark 0.110321 0.118574 0.930 0.352
L1.Tirol 0.307238 0.096008 3.200 0.001
L1.Vorarlberg 0.026759 0.084693 0.316 0.752
L1.Wien -0.024934 0.155322 -0.161 0.872
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189961 0.032224 5.895 0.000
L1.Burgenland 0.089135 0.020317 4.387 0.000
L1.Kärnten -0.007465 0.010646 -0.701 0.483
L1.Niederösterreich 0.245711 0.042452 5.788 0.000
L1.Oberösterreich 0.160104 0.041868 3.824 0.000
L1.Salzburg 0.040302 0.021555 1.870 0.062
L1.Steiermark 0.026145 0.028366 0.922 0.357
L1.Tirol 0.083908 0.022967 3.653 0.000
L1.Vorarlberg 0.054568 0.020260 2.693 0.007
L1.Wien 0.119244 0.037156 3.209 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108283 0.032239 3.359 0.001
L1.Burgenland 0.043182 0.020326 2.124 0.034
L1.Kärnten -0.013290 0.010651 -1.248 0.212
L1.Niederösterreich 0.174739 0.042472 4.114 0.000
L1.Oberösterreich 0.333957 0.041887 7.973 0.000
L1.Salzburg 0.101169 0.021565 4.691 0.000
L1.Steiermark 0.111916 0.028379 3.944 0.000
L1.Tirol 0.091733 0.022978 3.992 0.000
L1.Vorarlberg 0.061092 0.020270 3.014 0.003
L1.Wien -0.013536 0.037174 -0.364 0.716
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108868 0.060337 1.804 0.071
L1.Burgenland -0.045113 0.038042 -1.186 0.236
L1.Kärnten -0.045775 0.019934 -2.296 0.022
L1.Niederösterreich 0.139093 0.079489 1.750 0.080
L1.Oberösterreich 0.163981 0.078394 2.092 0.036
L1.Salzburg 0.283716 0.040360 7.030 0.000
L1.Steiermark 0.058567 0.053112 1.103 0.270
L1.Tirol 0.160900 0.043004 3.741 0.000
L1.Vorarlberg 0.098571 0.037936 2.598 0.009
L1.Wien 0.079344 0.069573 1.140 0.254
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053225 0.047322 1.125 0.261
L1.Burgenland 0.027224 0.029836 0.912 0.362
L1.Kärnten 0.052954 0.015634 3.387 0.001
L1.Niederösterreich 0.199058 0.062343 3.193 0.001
L1.Oberösterreich 0.331426 0.061484 5.390 0.000
L1.Salzburg 0.037210 0.031654 1.176 0.240
L1.Steiermark 0.009321 0.041656 0.224 0.823
L1.Tirol 0.122380 0.033728 3.628 0.000
L1.Vorarlberg 0.066995 0.029753 2.252 0.024
L1.Wien 0.100998 0.054565 1.851 0.064
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166457 0.056795 2.931 0.003
L1.Burgenland 0.005804 0.035808 0.162 0.871
L1.Kärnten -0.065743 0.018764 -3.504 0.000
L1.Niederösterreich -0.100763 0.074822 -1.347 0.178
L1.Oberösterreich 0.206933 0.073792 2.804 0.005
L1.Salzburg 0.055293 0.037991 1.455 0.146
L1.Steiermark 0.244145 0.049994 4.883 0.000
L1.Tirol 0.501802 0.040480 12.396 0.000
L1.Vorarlberg 0.063923 0.035709 1.790 0.073
L1.Wien -0.075515 0.065488 -1.153 0.249
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.145790 0.062944 2.316 0.021
L1.Burgenland -0.000975 0.039685 -0.025 0.980
L1.Kärnten 0.062523 0.020795 3.007 0.003
L1.Niederösterreich 0.170398 0.082923 2.055 0.040
L1.Oberösterreich -0.053120 0.081782 -0.650 0.516
L1.Salzburg 0.207580 0.042104 4.930 0.000
L1.Steiermark 0.139023 0.055407 2.509 0.012
L1.Tirol 0.058348 0.044862 1.301 0.193
L1.Vorarlberg 0.148742 0.039575 3.758 0.000
L1.Wien 0.123961 0.072579 1.708 0.088
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377396 0.037122 10.166 0.000
L1.Burgenland -0.002980 0.023405 -0.127 0.899
L1.Kärnten -0.020687 0.012264 -1.687 0.092
L1.Niederösterreich 0.206041 0.048905 4.213 0.000
L1.Oberösterreich 0.230787 0.048232 4.785 0.000
L1.Salzburg 0.038098 0.024831 1.534 0.125
L1.Steiermark -0.013261 0.032677 -0.406 0.685
L1.Tirol 0.089274 0.026458 3.374 0.001
L1.Vorarlberg 0.053656 0.023340 2.299 0.022
L1.Wien 0.044002 0.042804 1.028 0.304
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036628 0.112427 0.174390 0.140568 0.103041 0.083002 0.037925 0.211075
Kärnten 0.036628 1.000000 -0.024632 0.131671 0.050786 0.086539 0.443236 -0.065721 0.089990
Niederösterreich 0.112427 -0.024632 1.000000 0.318452 0.126408 0.279500 0.072397 0.156079 0.292576
Oberösterreich 0.174390 0.131671 0.318452 1.000000 0.218059 0.301570 0.169664 0.140436 0.241583
Salzburg 0.140568 0.050786 0.126408 0.218059 1.000000 0.127777 0.094882 0.108035 0.127241
Steiermark 0.103041 0.086539 0.279500 0.301570 0.127777 1.000000 0.138426 0.111751 0.039953
Tirol 0.083002 0.443236 0.072397 0.169664 0.094882 0.138426 1.000000 0.066911 0.152378
Vorarlberg 0.037925 -0.065721 0.156079 0.140436 0.108035 0.111751 0.066911 1.000000 -0.002705
Wien 0.211075 0.089990 0.292576 0.241583 0.127241 0.039953 0.152378 -0.002705 1.000000